//
// Created by Jisam on 2024/8/8 11:01.
// solve 4151 电影节
#include <bits/stdc++.h>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    while (cin >> n && n) {
        vector<pair<int, int>> a(n);
        for (int i = 0; i < n; i++) {
            cin >> a[i].first >> a[i].second;
        }
        sort(a.begin(), a.end(), [&](pair<int, int> p1, pair<int, int> p2) {
            return p1.second < p2.second;
        });
        int cnt = 1;
        int lo = a[0].first;
        int rh = a[0].second;
        for (auto [x, y]: a) {
//            cout << x << " " << y <<"\n";

            if(x >= rh){
                rh = y;
                cnt ++;
//                cout << "  ======  \n";
            }
        }
        cout << cnt <<"\n";

    }
    return 0;
}